#!/bin/bash
usrname=tom
usrpw=tom

read -p "localhost login:" name
read -p "Password:" pw


until [ "$usrname" = "$name" ] && [ "$pw" = "$usrpw" ]
do
	clear 
	echo "Login incorrect"
	echo "fail `date` on `tty`" >> login.log
	read -p "localhost login:" name
	read -p "Password:" pw
done
failstr=`cat login.log | grep fail`
successstr=`cat login.log | grep success`
if [ -n "$failstr" ]
then
	set `cat login.log | grep fail`
	echo "Last failed login:$2 $3 $4 $5 $6 $7 $8 $9"
fi

if [ -n "$successstr" ]
then
	set `cat login.log | grep success`
	echo "Last login:$2 $3 $4 $5 $6 $7 $8 $9"
fi
echo "welcome to `uname -srm`"
sed -i '/^fail/d' login.log
echo "success `date` on `tty`" >> login.log
